package com.bytedance.controller;

import com.bytedance.dataobject.B;
import com.bytedance.model.Result;
import com.bytedance.service.BService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/B")
public class BController {

    @Autowired
    private BService bService;

    @PostMapping
    public Result<B> add(@RequestBody B b) {
        return bService.add(b);
    }

    @PutMapping
    public Result<B> update(@RequestBody B b) throws Exception {
        return bService.update(b);
    }

    @PostMapping("/addList")
    public Result<List<B>> addList(@RequestBody List<B> bList) {
        return bService.add(bList);
    }

    @DeleteMapping("{a}/{c}")
    public Result<Integer> delete(@PathVariable String a, @PathVariable String c) {
        if (!StringUtils.hasText(c)) {
            c = "";
        }
        return bService.delete(a, c);
    }

    @GetMapping
    public Result<List<B>> getAll() {
        return bService.getAll();
    }

    @DeleteMapping("{c}")
    public Result<Integer> deleteByC(@PathVariable String c) {
        return bService.deleteByC(c);
    }
}
